package cn.dhn_app.horseman_app.service.impl;

import cn.dhn_app.horseman_app.entity.*;
import cn.dhn_app.horseman_app.mapper.horseman_accountMapper;
import cn.dhn_app.horseman_app.mapper.horseman_orderMapper;
import cn.dhn_app.horseman_app.mapper.menuMapper;
import cn.dhn_app.horseman_app.server.feign.FeignInterface;
import cn.dhn_app.horseman_app.service.HorsemanMenuService;
import cn.itcast.util.ResponseEntity;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import net.sf.json.JSON;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author lyy
 * @Description TODO
 * @PACKAGE_NAME: cn.dhn_app.horseman_app.service.impl
 * @ClassName HorsemanMenuServiceImpl
 * @Date 2020/8/27 15:58
 * @DAY_NAME_FULL: 星期四
 * @Version 1.0
 **/
@Service
public class HorsemanMenuServiceImpl implements HorsemanMenuService {

    @Resource
    private menuMapper menuMapper;

    @Resource
    private horseman_accountMapper horseman_accountMapper;

    @Resource
    private FeignInterface feignTokenInterface;

    @Resource
    private horseman_orderMapper horseman_orderMapper;



    /**
     * 功能描述: <br>
     * 〈所有菜单〉
     * @Author: lyy
     * @Date: 2020/8/27 16:14
     * @Param: []
     * @Return: cn.itcast.util.ResponseEntity
     */
    @Override
    public ResponseEntity MenuFindAll() {

        menuExample example = new menuExample();
        menuExample.Criteria criteria = example.createCriteria();
        criteria.getAllCriteria();
        List<menu> menuList = menuMapper.selectByExample(example);

        if(!menuList.isEmpty() && menuList.size()!=0){
            ResponseEntity responseEntity = new ResponseEntity();
            responseEntity.setTotal(Long.valueOf(menuList.size()));
            responseEntity.setData(menuList);
            responseEntity.setCode(200);
            responseEntity.setMessage("数据获取成功！！！");
            return responseEntity;
        }else{
            return new ResponseEntity().error_300();
        }
    }

    
    /**
     * 功能描述: <br>
     * 〈根据骑手openId查询骑手账户信息〉
     * @Author: lyy
     * @Date: 2020/10/16 15:59
     * @Param: [token, openId]
     * @Return: cn.itcast.util.ResponseEntity
     */
    @Override
    public ResponseEntity Horseman_Account(String token, String openId) {
        if(token.isEmpty()) return new ResponseEntity(401,"token参数为空！！！");
        token tokenEntity =this.feignTokenInterface.getToken(token);
        if(tokenEntity==null) return new ResponseEntity(402,"登陆超时,请重新登陆！！！");
        if(openId.isEmpty())return new ResponseEntity(401,"openId参数为空！！！");

        horseman_accountExample example = new horseman_accountExample();
        horseman_accountExample.Criteria criteria = example.createCriteria();
        criteria.andOpenIdEqualTo(openId);
        criteria.andAccountTypeidEqualTo(1);
        List<horseman_account> accountList = horseman_accountMapper.selectByExample(example);

        if(accountList.size()>0){
            return new ResponseEntity(200,"查询成功",accountList.get(0));
        }else{
            return new ResponseEntity(403,"查询失败");
        }
    }


    /**
     * 功能描述: <br>
     * 〈根据骑手openId获取骑手今日货重信息〉
     * @Author: lyy
     * @Date: 2020/10/21 15:49
     * @Param: [token, openId]
     * @Return: cn.itcast.util.ResponseEntity
     */
    @Override
    public ResponseEntity Today_Weight(String token, String openId) {
        if(token.isEmpty()) return new ResponseEntity(401,"token参数为空！！！");
//        token tokenEntity =this.feignTokenInterface.getToken(token);
//        if(tokenEntity==null) return new ResponseEntity(402,"登陆超时,请重新登陆！！！");
        if(openId.isEmpty())return new ResponseEntity(401,"openId参数为空！！！");

        List<JSONObject> entity = horseman_orderMapper.Today_Weight(openId);

        return new ResponseEntity(200,"",entity);
    }
}
